package org.lee.datasource.controller;

import org.lee.datasource.bean.User;
import org.lee.datasource.configuration.TargetDataSource;
import org.lee.datasource.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lizhe
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/user/{id}")
    @TargetDataSource("master")
    public User getUser(@PathVariable("id") Integer id) {
        return userService.getUser(id);
    }

    @PostMapping("addUser")
    @TargetDataSource("slave")
    public int addUser(@RequestBody User user) {
        return userService.addUser(user);
    }
}
